﻿// JScript 文件
var m_doc = new CtnDoc("m_doc","/Cfg/main.xml");
var m_vt = null;  //ToolId
var m_def = m_doc.objConstDef;

function initPage()
{
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth, screen.availHeight);
    //最大化
    m_doc.init();
}

//////////////////////文档对象//////////////////
function CtnDoc(name, cfgFile)
{
    this.name               = name;     //变量名

    this.cfgFile            = cfgFile;  //主配置文件名
    //存储变量
    this.objWndCtrl         = new CtnWndCtrl(this);     //窗体控制器

    this.objBarCtrl         = new CtnBarCtrl(this);     //Bar控制器

    this.objToolId          = new CtnToolId(this);      //ToolId
    this.objSysCfg          = new CtnSysCfg(this);      //系统配置
    this.objFramework       = new CtnFramework(this);   //框架调整
    this.objConstDef        = new CtnConstDef(this);    //常量定义
    this.arrMainMenu        = new Array();              //存储主菜单的配置文件名;
    this.loadCount          = 2;                        //需要加载页面的总数
    this.loadedNum          = 0;                        //存储已加载页面数
    this.arrFunc            = new Array();              //存储功能点列表    this.bValidate          = 0;                        //是否鉴权
    //接口
    this.init               = init_doc;             //初始化

    this.createWnd          = createWnd_doc;        //创建窗体
    this.createMainMenu     = createMainMenu_doc;   //创建主菜单    this.setActive          = setActive_doc;
    this.removeWnd          = removeWnd_doc;        //删除窗口

    this.createSideMenu     = createSideMenu_doc;   //创建侧边菜单
    this.getWndElem         = getWndElem_doc;       //根据Toolid获取窗口Iframe元素
    this.getWndObj          = getWndObj_doc;        //根据Toolid获取窗口对象
    this.getCurWnd          = getCurWnd_doc;        //获取当前窗体对象
    //函数
    this.initFunc           = initFunc_doc;         //功能点，用于鉴权
    
    this.initHeader         = initHeader_doc;       //初始化头部信息

    this.initMainMenu       = initMainMenu_doc;     //初始化主菜单
    this.initBody           = initBody_doc;         //初始化主体部分

    this.initFooter         = initFooter_doc;       //初始化尾部信息

    this.getClickStr        = getClickStr_doc;      //点击某个菜单项时，所要执行的所有函数

    this.showMainMenu       = showMainMenu_doc;     //显示主菜单
    this.loading            = loading_doc;          //页面加载信息

}

///////////////////系统配置/////////////////////
function CtnSysCfg(parent)
{
    this.parent             = parent;   //父级
    
    this.sysCssfile         = null;     //主风格文件

    this.frameworkCfgFile   = null;     //框架配置文件
    this.toolIdCfgFile      = null;     //ToolId配置文件
    this.sysMenuCfgFile     = null;     //系统菜单配置文件
    this.toolXmlNode        = null;     //初始化窗口XML对象
    this.mainMenuXmlNode    = null;     //初始化主菜单XML对象
    this.sideMenuXmlNode    = null;     //初始化侧边菜单XML对象
    
    //接口
    this.init               = init_cfg; //初始化函数

}

/////////////////窗体控制器//////////////
function CtnWndCtrl(parent)
{
    this.parent         = parent;   //父级
    this.name           = parent.name + ".objWndCtrl"; //变量名

    this.arrWnd         = new Array();  //所有窗体

    
    //闭合操作的相关属性和方法
    this.timer          = null;         //闭合定时器

    this.curActionWnd   = null;         //当前进行闭合操作的窗体

    this.wndLeft        = 0;            //窗体左部裁剪大小
    this.wndRight       = 0;            //窗体右部裁剪大小
    this.show           = show_wndctrl; //打开窗体
    this.hide           = hide_wndctrl; //关闭窗体
    this.move           = move_wndctrl; //移动窗体
    this.mouseOut       = mouseOut_wndctrl;     //鼠标移出动作（暂为实现）
    //接口
    this.append         = append_wndctrl;　     //添加窗体
    this.setActive      = setActive_wndctrl;    //激活窗体

    this.remove         = remove_wndctrl;       //删除窗体
    this.toggle         = toggle_wndctrl;       //切换闭合、固定状态
    this.closeCurWnd    = closeCurWnd_wndctrl;  //删除当前窗体
    
    //函数
    this.adjustWnd      = adjustWnd_wndctrl;    //调整所有子窗体高度
    this.getWndById     = getWndById_wndctrl;   //根据Id获取窗体
    this.getWndByType   = getWndByType_wndctrl; //根据类别获取窗体数组
    this.getCurWnd      = getCurWnd_wndctrl;    //获取当前窗体
}

/////////////////窗体对象///////////////
function CtnWnd(parent, tool)
{
    this.parent         = parent;   //父级
    this.tool           = tool;     //Tool
    this.wndCtrlId      = tool.target + "_wnd"; //窗体容器ID
    this.wndId          = "wnd_" + tool.id;     //窗体ID
    this.titleId        = "title_" + tool.id;   //标题ID
    this.toggleId       = "toggle_" + tool.id;  //切换标识ID
    this.toolbarId      = "toolbar_" + tool.id; //工具条

    this.contentId      = "content_" + tool.id; //窗体内容ID
    this.iframeId       = "iframe_" + tool.id;  //Iframe ID
    this.isCurWnd       = true; //是否当前窗体
    this.toolbarCtrl    = new CtnToolbarCtrl(); //工具条控制器
    
    //接口
    this.create         = create_wnd;   //创建窗体
    this.show           = show_wnd;     //显示窗体
    this.hide           = hide_wnd;     //隐藏窗体
    this.del            = delete_wnd;   //删除窗体
    this.update         = update_wnd;   //更新窗体
    
    //函数
}

////////////////选择栏控制器//////////////////
function CtnBarCtrl(parent)
{
    this.parent         = parent;   //父级
    this.name           = parent.name + ".objBarCtrl";  //变量名
    this.barlist        = null;

    this.arrBar         = new Array();          //所有Bar
    
    //接口
    this.append         = append_barctrl;       //添加Bar
    this.remove         = remove_barctrl;       //删除Bar
    this.setActive      = setActive_barctrl;    //激活Bar
    this.showAllBar     = showAllBar_barctrl;   //显示所有Bar
    
    //函数
    this.adjustBar      = adjustBar_barctrl;    //调整Bar
    this.getBarById     = getBarById_barctrl;   //根据ID获取Bar
    this.getBarByType   = getBarByType_barctrl; //根据类别获取Bar数组
}

/////////////////选择栏////////////////////////
function CtnBar(parent, tool)
{
    this.parent     = parent;   //父级
    this.tool       = tool;     //Tool
    this.barId      = "bar_" + tool.id; //Bar ID
    this.barXId     = "barX_" + tool.id;//BarX ID
    this.barYId     = "barY_" + tool.id;//BarY ID
    
    //接口
    this.create     = create_bar;   //创建
    this.show       = show_bar;     //显示
    this.hide       = hide_bar;     //隐藏
    this.del        = delete_bar;   //删除
    this.update     = update_bar;   //更新
    
    //函数
}

//////////////////////框架对象//////////////////
function CtnFramework(parent)
{
    this.parent             = parent;   //父级
    //初始数据
    this.frameworkHeight    = 750;  //整个窗口的高度(变动)
    this.frameworkWidth     = 1010; //整个窗口的宽度(变动)
    this.docHeadHeight      = 70;   //头部
    this.sysLogoWidth       = 400;  //网站标识
    this.docMenuHeight      = 25;   //主菜单

    this.leftBarYWidth      = 20;   //侧边视图选择栏

    this.leftViewWidth      = 180;  //左视图

    this.leftBarXHeight     = 20;   //底部视图选择栏

    this.mainBarHeight      = 20;   //主页面选择栏

    this.rightBarYWidth     = 20;   //侧边视图选择栏

    this.rightViewWidth     = 180;  //左视图

    this.rightBarXHeight    = 20;   //底部视图选择栏

    this.docFootHeight      = 25;   //尾部
    this.docBodyHeight      = 500;  //主体(变动)
    this.mainViewWidth      = 530;  //主视图(变动)
    this.leftWndHeight      = 470;  //左窗体(变动)
    this.mainWndHeight      = 470;  //主窗体(变动)
    this.rightWndHeight     = 470;  //右窗体(变动)
    //窗体内

    this.leftTitleHeight    = 25;   //左窗体标题栏高度
    this.leftToolbarHeight  = 25;   //左窗体工具条高度
    this.rightTitleHeight   = 25;   //右窗体标题栏高度
    this.rightToolbarHeight = 25;   //右窗体工具条高度
    this.mainToolbarHeight  = 25;   //主窗体工具条高度
    //属性

    this.sysLogoTitle       = null; //Logo标题
    this.sysLogoSrc         = null; //Logo图片地址
    this.sysLogoUrl         = null; //Logo响应地址
    this.docMenuEnable      = 1;    //是否允许主菜单

    this.docBodyLeftState   = -1;    //左视图状态

    this.docBodyRightState  = -1;   //右视图状态

    //接口
    this.init               = init_fw;  //初始化

    this.reset              = reset_fw; //重新调整
}

////////////////Tool对象//////////////////////
function CtnTool(id, name, target, url, image, content)
{
    this.id         = id;       //ID
    this.name       = name;     //名称
    this.target     = target;   //类别
    this.url        = url;      //地址
    this.image      = image;    //图标
    this.content    = content;  //Html内容
}

////////////////////ToolId////////////////////
function CtnToolId(parent)
{
    this.parent     = parent;       //父级
    
    this.init       = init_toolid; //初始化函数

}

///////////////////工具栏控制器//////////////////
function CtnToolbarCtrl(parent)
{
    this.parent     = parent;       //父级
    this.arrToolbar = new Array();  //工具对象集合
    
    this.append     = append_tb;    //添加
    this.del        = delete_tb;    //删除
    this.update     = update_tb;    //更新
    this.active     = active_tb;    //激活

}

/////////////////工具对象//////////////////////
function CtnToolBar(parent)
{
    this.parent     = parent;       //父级
}

///////////////////常量定义/////////////////////
function CtnConstDef(parent)
{
    this.parent         = parent;   //父级
    
    
    //框架ID
    this.loading        = "doc_loading";    //加载信息
    this.framework      = "framework";      //整个窗口
    this.docHead        = "doc_head";       //头部信息
    this.sysLogo        = "sys_logo";       //网站标识
    this.sysMenu        = "sys_menu";       //系统菜单
    this.docMenu        = "doc_menu";       //主菜单

    this.docBody        = "doc_body";       //主体信息
    this.leftBarY       = "left_barY";      //左侧边选择栏

    this.leftUlBarY     = "left_ul_barY";   //左侧边选择栏UL标签
    this.leftView       = "left_view";      //左视图

    this.leftWnd        = "left_wnd";       //左窗体

    this.leftBarX       = "left_barX";      //左底部选择栏

    this.leftUlBarX     = "left_ul_barX";   //左底部选择栏UL标签
    this.mainView       = "main_view";      //主视图

    this.mainWnd        = "main_wnd";       //主窗体

    this.mainBar        = "main_bar";       //主选择栏

    this.mainUlBar      = "main_ul_bar";    //主选择栏UL标签
    this.rightView      = "right_view";     //右视图

    this.rightWnd       = "right_wnd";      //右窗体

    this.rightBarX      = "right_barX";     //右底部选择栏

    this.rightUlBarX    = "right_ul_barX";  //右底部选择栏UL标签
    this.rightBarY      = "right_barY";     //右侧边选择栏

    this.rightUlBarY    = "right_ul_barY";  //右侧边选择栏UL标签
    this.docFoot        = "doc_foot";       //底部信息
    
    //
    this.sysMenuFile    = "SysMenu.aspx";   //系统菜单响应文件
    this.sideMenuFile   = "QQMenu.aspx";  //侧边菜单响应文件
}

//////////////////////文档对象//////////////////
function init_doc()
{
    //初始化系统配置文件

    this.objSysCfg.init();
    
    //初始化ToolId
    this.objToolId.init();
    
    //设为全局变量，便于调用

    m_vt = this.objToolId;
    //鉴权
    this.initFunc();

    //初始化框架

    this.objFramework.init();
    
    //初始化头部Logo和系统菜单

    this.initHeader();
    
    //初始化主菜单
    this.initMainMenu();
    
    //初始化侧边菜单和窗口
    this.initBody();
    
    //初始化尾部版权信息

    this.initFooter();
    
    this.loading();
}
function initFunc_doc()
{
    this.bValidate = parseInt($XML(this.objSysCfg.funcCfgNode, "validate"));
    if (!this.bValidate)
    {
        return;
    }
    var cfgFile = $XML(this.objSysCfg.funcCfgNode);
    if (cfgFile.indexOf("?") > -1)
    {
        cfgFile += "&" + (new Date()).getTime();
    }
    else
    {
        cfgFile += "?" + (new Date()).getTime();
    }
    var text = CtnTrans.getText(cfgFile);
    if (text)
    {
        var arr = text.split(",");
        for (var i = 0; i < arr.length; i++)
        {
            this.arrFunc.push(parseInt(arr[i]));//与不是功能点，无须验证的合并
        }
    }
}

function initHeader_doc()
{
   $(m_def.sysLogo).innerHTML = '<a href="' + this.objFramework.sysLogoUrl
                         + '"><img alt="' + this.objFramework.sysLogoTitle 
                         + '" title="' + this.objFramework.sysLogoTitle 
                         + '" src="' + this.objFramework.sysLogoSrc 
                         + '" style="border:0;"></img></a>';
    $(m_def.sysMenu).innerHTML = '<iframe id="iframe_sysmenu" src="sysmenu.htm#' 
                        + this.objSysCfg.sysMenuCfgFile + '" height="100%"'
                        + 'width="'+ (this.objFramework.frameworkWidth - this.objFramework.sysLogoWidth - 10)
                        + 'px" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';
}

function initMainMenu_doc()
{
    var xmlNode = this.objSysCfg.mainMenuXmlNode;
    if (xmlNode)
    {
        var cfgFile = $XML(xmlNode);
        this.createMainMenu(cfgFile);
    }
    else
    {
        this.createMainMenu(null);
    }
}

function initBody_doc()
{
    var toolXmlNode = this.objSysCfg.toolXmlNode;
    var tools = toolXmlNode.selectNodes("tool");
    this.loadCount += tools.length;//加载页面个数
    for (var i = 0; i < tools.length; i++)
    {
        var tool = new CtnTool();
        //判断Id变量和Id值是否为空

        var id = $XML(tools[i], "id");
        if (isNaN(parseInt(id)))
        {
            if (!id || !this.objToolId[id])
            {
                continue;
            }
            tool.id = this.objToolId[id];
        }
        else
        {
            tool.id = id;
        }
        tool.id = this.objToolId[id];
        tool.name = $XML(tools[i], "name");
        tool.target = $XML(tools[i], "target");
        tool.url = $XML(tools[i], "url");
        this.createWnd(tool);
    }
    
    var sideMenuXmlNode = this.objSysCfg.sideMenuXmlNode;
    var sideMenus = sideMenuXmlNode.selectNodes("menu");
    this.loadCount += sideMenus.length;//加载页面个数
    for (var i = 0; i < sideMenus.length; i++)
    {
        var tool = new CtnTool();
        //判断Id变量和Id值是否为空
        var id = $XML(sideMenus[i], "id");
        if (isNaN(parseInt(id)))
        {
            if (!id || !this.objToolId[id])
            {
                continue;
            }
            tool.id = this.objToolId[id];
        }
        else
        {
            tool.id = id;
        }
        tool.name = $XML(sideMenus[i], "name");
        tool.target = $XML(sideMenus[i], "target");
        tool.url = $XML(sideMenus[i], "url");
        this.createSideMenu(tool);
    }
}

function initFooter_doc()
{
    
}

function createWnd_doc(tool)
{
    if(!tool.id)
    {
        CtnDlg.warning("ToolId未定义");
        return;
    }
    else if (!CanOperFunc(tool.id))//鉴权
    {
        return;
    }
    if ((new String(tool.target)) =="null" || !tool.target)
    {
        return;
    }
    var objWnd = this.objWndCtrl.append(tool);
//    if (objWnd)
//    {
//        //加载信息
//        $(objWnd.iframeId).onload = function()
//        {
//            top.m_doc.loading();
//        }
//    }
    if (tool.target != "float")
    {
        this.objBarCtrl.append(tool);
    }
}
function setActive_doc(id)
{
    this.objBarCtrl.setActive(id);
    this.objBarCtrl.adjustBar(id);
    this.objWndCtrl.setActive(id);
}
function removeWnd_doc(id)
{
    this.objBarCtrl.remove(id);
}
function createMainMenu_doc(file)
{
    //如果file为空，则隐藏主菜单

    if (file)
    {
        //判断是否已经存在
        var idx = -1;
        for (var i = 0; i < this.arrMainMenu.length; i++)
        {
            var t = this.arrMainMenu[i].lastIndexOf("&");
            if (t == -1)
            {
                t = this.arrMainMenu[i].lastIndexOf("?");
            }
            var src = this.arrMainMenu[i].substring(0, t);
            if (src == file)
            {
                idx = i;
                $("doc_menu_" + i).show();
            }
            else
            {
                $("doc_menu_" + i).hide();
            }
        }
        //如果不存在则新建并存储

        if (idx == -1)
        {
            idx = this.arrMainMenu.length;
            if (file.indexOf("?") > -1)
            {
                file += "&" + (new Date()).getTime();
            }
            else
            {
                file += "?" + (new Date()).getTime();
            }
            var xmlDoc = CtnTrans.getXml(file);
            if (xmlDoc)
            {
                try
                {
                    this.showMainMenu(xmlDoc, idx);
                    this.arrMainMenu.push(file);
                    if (!this.objFramework.docMenuEnable)
                    {
                        this.objFramework.docMenuEnable = true;
                        this.objFramework.reset();
                    }
                }
                catch(e)
                {
                    CtnError.show(e);
                }
            }
        }
        else
        {
            if (!this.objFramework.docMenuEnable)
            {
                this.objFramework.docMenuEnable = true;
                this.objFramework.reset();
            }
        }
    }
    else
    {
        if (this.objFramework.docMenuEnable)
        {
            this.objFramework.docMenuEnable = false;
            this.objFramework.reset();
        }
    }
}

function createSideMenu_doc(tool)
{
    if (!tool)
    {
        return;
    }
    tool.url = "qqmenu.htm#" + escape(tool.url);
    this.createWnd(tool);
}

function getWndElem_doc(toolid)
{
    elem = null;
    var objWnd = this.objWndCtrl.getWndById(toolid);
    if (objWnd)
    {
        elem = $(objWnd.iframeId).contentWindow;
    }
    return elem;
}
function getWndObj_doc(toolid)
{
    var objWnd = this.objWndCtrl.getWndById(toolid);
    return objWnd;
}
function getCurWnd_doc(target)
{
    return this.objWndCtrl.getCurWnd(target);
}
function getClickStr_doc(item)
{
    var vClick = "";
    //创建侧边菜单
    var sideMenus = item.selectNodes("sidemenu");
    for (var j = 0; j < sideMenus.length; j++)
    {
        var id = $XML(sideMenus[j], "id");
        if (isNaN(parseInt(id)))
        {
            id = "top.m_vt." + id;
        }
        if ($XML(sideMenus[j], "target"))
        {
            vClick += "top.m_doc.createSideMenu(new top.CtnTool(";
            vClick += id;
            vClick += ",'" + $XML(sideMenus[j], "name");
            vClick += "','" + $XML(sideMenus[j], "target");
            vClick += "','" + $XML(sideMenus[j], "url");
            vClick += "','" + $XML(sideMenus[j], "image");
            vClick += "','" + $XML(sideMenus[j], "content");
            vClick += "'));";
        }
        //简单参数
        if ($XML(sideMenus[j], "param"))
        {
            vClick += "top.ExecuteATool(" + id + ", '" + $XML(sideMenus[j], "param") + "');";
        }
        else
        {
            vClick += "top.ExecuteATool(" + id + ");";
        }
    }
    //创建主菜单

    var mainMenu = item.selectSingleNode("mainmenu");
    if (mainMenu)
    {
        vClick += "top.m_doc.createMainMenu('";
        vClick += $XML(mainMenu, "file");
        vClick += "');";
    }
    
    //响应Tool,创建窗口,可以从Menu中或Menu的tool项中提取
    if ($XML(item, "id"))
    {
        var id = $XML(item, "id");
        if (isNaN(parseInt(id)))
        {
            id = "top.m_vt." + id;
        }
        if ($XML(item, "target"))
        {
            vClick += "top.m_doc.createWnd(new top.CtnTool(";
            vClick += id;
            vClick += ",'" + $XML(item, "name");
            vClick += "','" + $XML(item, "target");
            vClick += "','" + $XML(item, "url");
            vClick += "','" + $XML(item, "image");
            vClick += "','" + $XML(item, "content");
            vClick += "'));";
        }
        if ($XML(item, "param"))
        {
            vClick += "top.ExecuteATool(" + id + ", '" + $XML(item, "param") + "');";
        }
        else
        {
            vClick += "top.ExecuteATool(" + id + ");";
        }
    }
    else
    {
        var tools = item.selectNodes("tool");
        for (var j = 0; j < tools.length; j++)
        {
            var id = $XML(tools[j], "id");
            if (isNaN(parseInt(id)))
            {
                id = "top.m_vt." + id;
            }
            if ($XML(tools[j], "target"))
            {
                vClick += "top.m_doc.createWnd(new top.CtnTool(";
                vClick += id;
                //tool中没则到父级Menu中获取
                if ($XML(tools[j], "name"))
                    vClick += ",'" + $XML(tools[j], "name");
                else
                    vClick += ",'" + $XML(item, "name");
                vClick += "','" + $XML(tools[j], "target");
                vClick += "','" + $XML(tools[j], "url");
                //tool中没则到父级Menu中获取

                if ($XML(tools[j], "image"))
                    vClick += "','" + $XML(tools[j], "image");
                else
                    vClick += "','" + $XML(item, "image");
                vClick += "','" + $XML(tools[j], "content");
                vClick += "'));";
            }
            if ($XML(tools[j], "param"))
            {
                vClick += "top.ExecuteATool(" + id + ", '" + $XML(tools[j], "param") + "');";
            }
            else
            {
                vClick += "top.ExecuteATool(" + id + ");";
            }
        }
    }
    
    return vClick;
}

function showMainMenu_doc(xmlDoc, idx)
{
    var cfg = xmlDoc.selectSingleNode("//menus");
    if (cfg == null)
    {
        throw("菜单配置文件不合法!");
    }
    
    var vHtml = new String();
    vHtml += '<ul>';
    var arrMenu = cfg.selectNodes("menu");
    for (var i = 0; i < arrMenu.length; i++)
    {
        var vHtml2= '<li>';
        arrMenu2 = arrMenu[i].selectNodes("menu");
        //判断是否有子元素
        if (arrMenu2.length > 0)
        {
            vHtml2 += '<a class="hide" href="#" title="' + $XML(arrMenu[i], "name") ;
            vHtml2 += '" onclick="' + this.getClickStr(arrMenu[i]) + '">' + $XML(arrMenu[i], "name") + '</a>';
            
            vHtml2 += '<!--[if lte IE 6]>';
            vHtml2 += '<a href="#" title="' + $XML(arrMenu[i], "name") ;
            vHtml2 += '" onclick="' + this.getClickStr(arrMenu[i]) + '">' + $XML(arrMenu[i], "name");
            vHtml2 += '<table><tr><td>';
            vHtml2 += '<![endif]-->';
            
            vHtml2 += '<ul>'
            
            for (var j = 0; j < arrMenu2.length; j++)
            {
                var vHtml3= '<li>';
                arrMenu3 = arrMenu2[j].selectNodes("menu");
                //判断是否有子元素
                if (arrMenu3.length > 0)
                {
                    vHtml3 += '<a class="hide" href="#" title="' + $XML(arrMenu2[j], "name") ;
                    vHtml3 += '" onclick="' + this.getClickStr(arrMenu2[j]) + '">' + $XML(arrMenu2[j], "name") + '</a>';
                    
                    vHtml3 += '<!--[if lte IE 6]>';
                    vHtml3 += '<a class="sub" href="#" title="' + $XML(arrMenu2[j], "name") ;
                    vHtml3 += '" onclick="' + this.getClickStr(arrMenu2[j]) + '">' + $XML(arrMenu2[j], "name");
                    vHtml3 += '<table><tr><td>';
                    vHtml3 += '<![endif]-->';
                    
                    vHtml3 += '<ul>'
                    for (var k = 0; k < arrMenu3.length; k++)
                    {
                        //如果没有儿子，且没tool权限
                        if (!CanOperMenu(arrMenu3[k]))
                        {
                            continue;
                        }
                        vHtml3 += '<li><a href="#" title="' + $XML(arrMenu3[k], "name") ;
                        vHtml3 += '" onclick="' + this.getClickStr(arrMenu3[k]) + '">' + $XML(arrMenu3[k], "name");
                        vHtml3 += '</a></li>';
                    }
                    vHtml3 += '</ul>';
                    
                    vHtml3 += '<!--[if lte IE 6]>';
                    vHtml3 += '</td></tr></table>';
                    vHtml3 += '</a>';
                    vHtml3 += '<![endif]-->';
                }
                else
                {
                    //如果没有儿子，且没tool权限
                    if (!CanOperMenu(arrMenu2[j]))
                    {
                        continue;
                    }
                    vHtml3 += '<a href="#" title="' + $XML(arrMenu2[j], "name");
                    vHtml3 += '" onclick="' + this.getClickStr(arrMenu2[j]) + '">' + $XML(arrMenu2[j], "name") + '</a>';
                }
                vHtml3 += '</li>';
                vHtml2 += vHtml3;
            }
           
            
            vHtml2 += '</ul>';
            
            vHtml2 += '<!--[if lte IE 6]>';
            vHtml2 += '</td></tr></table>';
            vHtml2 += '</a>';
            vHtml2 += '<![endif]-->';
        }
        else
        {
            //如果没有儿子，且没tool权限
            if (!CanOperMenu(arrMenu[i]))
            {
                continue;
            }
            vHtml2 += '<a href="#" title="' + $XML(arrMenu[i], "name") ;
            vHtml2 += '" onclick="' + this.getClickStr(arrMenu[i]) + '">' + $XML(arrMenu[i], "name") + '</a>';
        }
        vHtml2 += '</li>';
        vHtml += vHtml2;
    }
    vHtml += '</ul>';
    //$(m_def.docMenu).insertAdjacentHTML("beforeEnd", '<div id="doc_menu_' + idx + '" class="menu">' + vHtml + '</div>');
    new Insertion.Bottom("doc_menu", '<div id="doc_menu_' + idx + '" class="menu">' + vHtml + '</div>');
 //   $(m_def.docMenu).insertAdjacentHTML("beforeEnd", '<textarea>' + vHtml.replace("<", "&lt;").replace(">","&gt;") + '</textarea>');
    
}

function loading_doc(msg)
{
//    this.loadedNum += 1;
//    if (this.loadedNum == this.loadCount)
//    {
        $(m_def.framework).style.visibility = "visible";
        $(m_def.loading).hide();
//    }
//    
//    if(msg)
//    {
//        $(m_def.loading).innerHTML = msg;
//    }
}
///////////////////常量定义/////////////////////

///////////////////系统配置/////////////////////
function init_cfg()
{
    var cfgFile = this.parent.cfgFile;
    if (cfgFile.indexOf("?") > -1)
    {
        cfgFile += "&" + (new Date()).getTime();
    }
    else
    {
        cfgFile += "?" + (new Date()).getTime();
    }
    var xmlDoc = CtnTrans.getXml(cfgFile);
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
    }
    var cfg = xmlDoc.selectSingleNode("//syscfg");
    if (cfg == null)
    {
        throw("系统配置文件不合法");
    }
    
    this.sysCssfile         = $XML(cfg.selectSingleNode("syscssfile"));
    this.frameworkCfgFile   = $XML(cfg.selectSingleNode("frameworkcfgfile"));
    this.toolIdCfgFile      = $XML(cfg.selectSingleNode("toolidcfgfile"));
    
    this.sysMenuCfgFile     = $XML(cfg.selectSingleNode("sysmenucfgfile"));
    this.sysMenuFile        = $XML(cfg.selectSingleNode("sysmenufile"));
    this.sideMenuFile       = $XML(cfg.selectSingleNode("sidemenufile"));
    
    this.funcCfgNode        = cfg.selectSingleNode("funccfgfile");
    this.toolXmlNode        = cfg.selectSingleNode("inittools");
    this.mainMenuXmlNode    = cfg.selectSingleNode("initmainmenu");
    this.sideMenuXmlNode    = cfg.selectSingleNode("initsidemenus");
}

////////////////////ToolId////////////////////
function init_toolid()
{
    var cfgFile = this.parent.objSysCfg.toolIdCfgFile;
    if (!cfgFile)
    {
        throw("不存在ToolId配置文件");
    }
    if (cfgFile.indexOf("?") > -1)
    {
        cfgFile += "&" + (new Date()).getTime();
    }
    else
    {
        cfgFile += "?" + (new Date()).getTime();
    }
    var xmlDoc = CtnTrans.getXml(cfgFile);
    var cfg = xmlDoc.selectSingleNode("//toolid");
    if (cfg == null)
    {
        throw("ToolId配置文件不合法");
    }
    var arrFunc = this.parent.arrFunc;
    var arrGroup = cfg.selectNodes("group");
    for (var i = 0; i < arrGroup.length; i++)
    {
        var arrItem = arrGroup[i].selectNodes("item");
        for (var j = 0; j < arrItem.length; j++)
        {
            //读取ToolId变量名和值并转换为该类的变量名和值
            var key = $XML(arrGroup[i], "name") + "_" + $XML(arrItem[j], "name");
            var value = $XML(arrItem[j], "id", "int");
            this[key] = value;
            //不是功能点，则将其加入权限列表中
            if ($XML(arrItem[j], "validate") == "0")
            {
                arrFunc.push(value);
            }
        }
    }
}
//////////////////////框架对象//////////////////
function init_fw()
{
    var cfgFile = this.parent.objSysCfg.frameworkCfgFile;
    if (!cfgFile)
    {
        throw("不存在框架配置文件");
    }
    var xmlDoc = CtnTrans.getXml(cfgFile);
    var cfg = xmlDoc.selectSingleNode("//framework");
    if (cfg == null)
    {
        throw("网站框架配置文件不合法");
    }

    this.docHeadHeight = $XML(cfg.selectSingleNode("dochead"), "height", "int");  //头部
    this.sysLogoWidth = $XML(cfg.selectSingleNode("dochead/syslogo"), "width", "int");  //网站标识
    this.docMenuHeight = $XML(cfg.selectSingleNode("docmenu"), "height", "int");  //主菜单

    this.leftBarYWidth = $XML(cfg.selectSingleNode("docbody/leftbarY"), "width", "int"); //侧边视图选择栏

    this.leftViewWidth = $XML(cfg.selectSingleNode("docbody/leftview"), "width", "int"); //浮动窗

    this.leftBarXHeight = $XML(cfg.selectSingleNode("docbody/leftview/leftbarX"), "height", "int"); //底部视图选择栏

    this.mainBarHeight = $XML(cfg.selectSingleNode("docbody/mainview/mainbar"), "height", "int");  //主页面选择栏

    this.rightViewWidth = $XML(cfg.selectSingleNode("docbody/rightview"), "width", "int");  //浮动窗

    this.rightBarXHeight = $XML(cfg.selectSingleNode("docbody/rightview/rightbarX"), "height", "int");  //底部视图选择栏

    this.rightBarYWidth = $XML(cfg.selectSingleNode("docbody/rightbarY"), "width", "int");  //侧边视图选择栏

    this.docFootHeight = $XML(cfg.selectSingleNode("docfoot"), "height", "int");  //尾部 
    this.leftTitleHeight = $XML(cfg.selectSingleNode("docbody/leftview/leftwnd/title"), "height", "int"); //浮动窗

    this.leftToolbarHeight = $XML(cfg.selectSingleNode("docbody/leftview/leftwnd/toolbar"), "height", "int"); //底部视图选择栏
    this.mainToolbarHeight = $XML(cfg.selectSingleNode("docbody/mainview/mainwnd/toolbar"), "height", "int");  //主页面选择栏

    this.rightTitleHeight = $XML(cfg.selectSingleNode("docbody/rightview/rightwnd/title"), "height", "int");  //浮动窗
    this.rightToolbarHeight = $XML(cfg.selectSingleNode("docbody/rightview/rightwnd/toolbar"), "height", "int");  //底部视图选择栏
    
    this.sysLogoTitle = $XML(cfg.selectSingleNode("dochead/syslogo"), "title");
    this.sysLogoSrc = $XML(cfg.selectSingleNode("dochead/syslogo"), "src");
    this.sysLogoUrl = $XML(cfg.selectSingleNode("dochead/syslogo"), "url");
    this.docMenuEnable = $XML(cfg.selectSingleNode("docmenu"), "enable", "int");
    this.docBodyLeftState = $XML(cfg.selectSingleNode("docbody"), "leftstate", "int");
    this.docBodyRightState = $XML(cfg.selectSingleNode("docbody"), "rightstate", "int");
    
    $(m_def.docHead).style.height  = this.docHeadHeight + "px";
    $(m_def.sysLogo).style.width   = this.sysLogoWidth + "px";
    $(m_def.docMenu).style.height  = this.docMenuHeight + "px";
    $(m_def.leftBarY).style.width  = this.leftBarYWidth + "px";
    $(m_def.leftView).style.width  = this.leftViewWidth + "px";
    $(m_def.leftBarX).style.height = this.leftBarXHeight + "px";
    $(m_def.mainBar).style.height  = this.mainBarHeight + "px";
    $(m_def.rightView).style.width = this.rightViewWidth + "px";
    $(m_def.rightBarX).style.height= this.rightBarXHeight + "px";
    $(m_def.rightBarY).style.width = this.rightBarYWidth + "px";
    $(m_def.docFoot).style.height  = this.docFootHeight + "px";
    
    //加上boder,margin等值,以方便动态调整

    this.docHeadHeight = this.docHeadHeight*1 + 5;
    this.sysLogoWidth = this.sysLogoWidth*1 + 5;
    this.docMenuHeight = this.docMenuHeight*1 + 5;
    this.leftBarYWidth = this.leftBarYWidth*1 + 4;
    this.leftViewWidth = this.leftViewWidth*1 + 3;
    this.leftBarXHeight = this.leftBarXHeight*1 + 5;
    this.mainBarHeight = this.mainBarHeight*1 + 5;
    this.rightViewWidth = this.rightViewWidth*1 + 3;
    this.rightBarXHeight = this.rightBarXHeight*1 + 5;
    this.rightBarYWidth = this.rightBarYWidth*1 + 4;
    this.docFootHeight = this.docFootHeight*1 + 5;
    
    this.frameworkHeight = document.documentElement.clientHeight;
    this.frameworkWidth = document.documentElement.clientWidth;
    
    this.reset();
}

function reset_fw()
{
    
    if (this.docMenuEnable == 1)
    {
        this.docBodyHeight = this.frameworkHeight - this.docHeadHeight - this.docMenuHeight - this.docFootHeight;
        $(m_def.docMenu).show();
    }
    else
    {
        this.docBodyHeight = this.frameworkHeight - this.docHeadHeight - this.docFootHeight;
        $(m_def.docMenu).hide();
    }
    
    this.mainWndHeight = this.docBodyHeight - this.mainBarHeight;
    
    if (this.docBodyLeftState == -1 && this.docBodyRightState == -1)
    {
        this.mainViewWidth = this.frameworkWidth;
        //$(m_def.leftBarX).hide();
        $(m_def.leftBarY).hide();
        $(m_def.leftView).hide();
        //$(m_def.rightBarX).hide();
        $(m_def.rightBarY).hide();
        $(m_def.rightView).hide();
    }
    else if (this.docBodyLeftState == -1 && this.docBodyRightState == 0)
    {
        this.mainViewWidth = this.frameworkWidth - this.rightBarYWidth; 
        this.rightWndHeight = this.docBodyHeight; 
        //$(m_def.leftBarX).hide();
        $(m_def.leftBarY).hide();
        $(m_def.leftView).hide();
        $(m_def.rightBarX).hide();
        $(m_def.rightBarY).show();
        $(m_def.rightView).show();
        $(m_def.rightView).style.position = "absolute";
        $(m_def.rightView).style.clip = "rect(0 0 0 0)";
        $(m_def.rightView).style.left = (this.frameworkWidth - this.rightBarYWidth - 5) + "px";
    }
    else if (this.docBodyLeftState == -1 && this.docBodyRightState == 1)
    {
        this.mainViewWidth = this.frameworkWidth - this.rightViewWidth; 
        this.rightWndHeight = this.docBodyHeight - this.rightBarXHeight; 
        //$(m_def.leftBarX).show();
        $(m_def.leftBarY).hide();
        $(m_def.leftView).hide();
        $(m_def.rightBarX).show();
        $(m_def.rightBarY).hide();
        $(m_def.rightView).show();
        $(m_def.rightView).style.position = "static";
    }
    else if (this.docBodyLeftState == 0 && this.docBodyRightState == -1)
    {
        this.mainViewWidth = this.frameworkWidth - this.leftBarYWidth; 
        this.leftWndHeight = this.docBodyHeight; 
        $(m_def.leftBarX).hide();
        $(m_def.leftBarY).show();
        $(m_def.leftView).show();
        $(m_def.leftView).style.position = "absolute";
        $(m_def.leftView).style.clip = "rect(0 0 0 0)";
        $(m_def.leftView).style.left = (this.leftBarYWidth - this.leftViewWidth) + "px";
        //$(m_def.leftView).style.top = (this.docHeadHeight + this.docMenuHeight) + "px";
        //$(m_def.rightBarX).show();
        $(m_def.rightBarY).hide();
        $(m_def.rightView).hide();
        //$(m_def.rightView).style.position = "static";
    }
    else if (this.docBodyLeftState == 0 && this.docBodyRightState == 0)
    {
        this.mainViewWidth = this.frameworkWidth - this.leftBarYWidth - this.rightBarYWidth; 
        this.leftWndHeight = this.docBodyHeight; 
        this.rightWndHeight = this.docBodyHeight; 
        $(m_def.leftBarX).hide();
        $(m_def.leftBarY).show();
        $(m_def.leftView).show();
        $(m_def.leftView).style.position = "absolute";
        $(m_def.leftView).style.clip = "rect(0 0 0 0)";
        $(m_def.leftView).style.left = (this.leftBarYWidth - this.leftViewWidth) + "px";
        $(m_def.rightBarX).hide();
        $(m_def.rightBarY).show();
        $(m_def.rightView).show();
        $(m_def.rightView).style.position = "absolute";
        $(m_def.rightView).style.clip = "rect(0 0 0 0)";
        $(m_def.rightView).style.left = (this.frameworkWidth - this.rightBarYWidth - 5) + "px";
    }
    else if (this.docBodyLeftState == 0 && this.docBodyRightState == 1)
    {
        this.mainViewWidth = this.frameworkWidth - this.leftBarYWidth - this.rightViewWidth; 
        this.leftWndHeight = this.docBodyHeight; 
        this.rightWndHeight = this.docBodyHeight - this.rightBarXHeight; 
        $(m_def.leftBarX).hide();
        $(m_def.leftBarY).show();
        $(m_def.leftView).show();
        $(m_def.leftView).style.position = "absolute";
        $(m_def.leftView).style.clip = "rect(0 0 0 0)";
        $(m_def.leftView).style.left = (this.leftBarYWidth - this.leftViewWidth) + "px";
        $(m_def.rightBarX).show();
        $(m_def.rightBarY).hide();
        $(m_def.rightView).show();
        $(m_def.rightView).style.position = "static";
    }
    else if (this.docBodyLeftState == 1 && this.docBodyRightState == -1)
    {
        this.mainViewWidth = this.frameworkWidth - this.leftViewWidth; 
        this.leftWndHeight = this.docBodyHeight - this.leftBarXHeight; 
        $(m_def.leftBarX).show();
        $(m_def.leftBarY).hide();
        $(m_def.leftView).show();
        $(m_def.leftView).style.position = "static";
        //$(m_def.rightBarX).show();
        $(m_def.rightBarY).hide();
        $(m_def.rightView).hide();
        //$(m_def.rightView).style.position = "static";
    }
    else if (this.docBodyLeftState == 1 && this.docBodyRightState == 0)
    {
        this.mainViewWidth = this.frameworkWidth - this.leftViewWidth - this.rightBarYWidth; 
        this.leftWndHeight = this.docBodyHeight - this.leftBarXHeight; 
        this.rightWndHeight = this.docBodyHeight; 
        $(m_def.leftBarX).show();
        $(m_def.leftBarY).hide();
        $(m_def.leftView).show();
        $(m_def.leftView).style.position = "static";
        $(m_def.rightBarX).hide();
        $(m_def.rightBarY).show();
        $(m_def.rightView).show();
        $(m_def.rightView).style.position = "absolute";
        $(m_def.rightView).style.clip = "rect(0 0 0 0)";
        $(m_def.rightView).style.left = (this.frameworkWidth - this.rightBarYWidth - 5) + "px";
    }
    else if (this.docBodyLeftState == 1 && this.docBodyRightState == 1)
    {
        this.mainViewWidth = this.frameworkWidth - this.leftViewWidth - this.rightViewWidth; 
        this.leftWndHeight = this.docBodyHeight - this.leftBarXHeight; 
        this.rightWndHeight = this.docBodyHeight - this.rightBarXHeight; 
        $(m_def.leftBarX).show();
        $(m_def.leftBarY).hide();
        $(m_def.leftView).show();
        $(m_def.leftView).style.position = "static";
        $(m_def.rightBarX).show();
        $(m_def.rightBarY).hide();
        $(m_def.rightView).show();
        $(m_def.rightView).style.position = "static";
    }
    
    $(m_def.framework).style.height = this.frameworkHeight + "px";
    $(m_def.framework).style.width  = this.frameworkWidth + "px";
    $(m_def.docBody).style.height   = this.docBodyHeight + "px";
    $(m_def.mainView).style.width   = this.mainViewWidth + "px";
    $(m_def.mainWnd).style.height   = this.mainWndHeight + "px";
    $(m_def.leftWnd).style.height   = this.leftWndHeight + "px";
    $(m_def.rightWnd).style.height  = this.rightWndHeight + "px";
    
    //调整窗体大小
    var objWndCtrl = this.parent.objWndCtrl;
    if (objWndCtrl)
    {
        for (var i = 0; i < objWndCtrl.arrWnd.length; i++)
        {
            objWndCtrl.adjustWnd(objWndCtrl.arrWnd[i]);
        }
    }
}

/////////////////窗体控制器//////////////
function append_wndctrl(tool)
{
    var objWnd = this.getWndById(tool.id);
    if (objWnd)
    {
        objWnd.update(tool);
    }
    else
    {
        objWnd = new CtnWnd(this, tool);
        objWnd.create();
        this.arrWnd.push(objWnd);
    }
    this.adjustWnd(objWnd);
    this.setActive(tool.id);
    //如果窗体容器还没显示，则左窗体显示为固定，右窗体显示为浮动

    var framework = this.parent.objFramework;
    if ((framework.docBodyLeftState==-1) && (tool.target == "left"))
    {
        framework.docBodyLeftState = 1;
        framework.reset();
    }
    else if ((framework.docBodyRightState==-1) && (tool.target == "right"))
    {
        framework.docBodyRightState = 1;
        framework.reset();
    }
    return objWnd;
}

function setActive_wndctrl(id)
{
    var objWnd = this.getWndById(id);
    for (var i = 0; i < this.arrWnd.length; i++)
    {
        if (this.arrWnd[i].tool.id == id)
        {
            this.arrWnd[i].show();
        }
        else if(objWnd.tool.target == this.arrWnd[i].tool.target)
        {
            this.arrWnd[i].hide();
        }
    }
}

function remove_wndctrl(id)
{
    for (var i = 0; i < this.arrWnd.length; i++)
    {
        if (this.arrWnd[i].tool.id == id)
        {
            //如果是当前页，需要另设一个当前页
//            if (this.arrWnd[i].isCurWnd)
//            {
                var target = this.arrWnd[i].tool.target;
                //从数组中删除
                this.arrWnd[i].del();
                this.arrWnd.splice(i, 1);
                var arrWnd = this.getWndByType(target);
                if (arrWnd.length == 0)
                {
                    //隐藏窗体容器和Bar容器
                    if (target == "left")
                    {
                        this.parent.objFramework.docBodyLeftState  = -1;
                        this.parent.objFramework.reset();
                    }
                    else if(target == "right")
                    {
                        this.parent.objFramework.docBodyRightState  = -1;
                        this.parent.objFramework.reset();
                    }
                    else{}
                }
//            }
            break;
        }
    }
}

function mouseOut_wndctrl(evt, elem, id)
{
    if (CtnBrowser.FF)
    {
        var x = evt.clientX + document.body.scrollLeft;
        var y = evt.clientY + document.body.scrollTop ;
        var vLeft = elem.offsetLeft;
        var vTop = elem.offsetTop;
        var w = elem.offsetWidth;
        var h = elem.offsetHeight;
        if(y < vTop || y > (h + vTop) || x > vLeft + w || x<vLeft )
        {
            this.hide(id);
        }
    }
    else if(CtnBrowser.IE)
    {
        if(elem.contains(event.toElement ) == false)
        {
            this.hide(id);
        }
    }
   
}

function show_wndctrl(id)
{
    
//    if (this.curActionWnd && this.curActionWnd.tool.id == id)
//    {
//        this.move(true);
//        return;
//    }
    this.curActionWnd = this.getWndById(id);
    if (this.timer)
    {
        clearTimeout(this.timer);
    }
    this.setActive(id);
    
    this.parent.objFramework.reset();
    if(this.curActionWnd.tool.target == "left")
    {
        this.wndLeft = this.parent.objFramework.leftViewWidth;
        this.wndRight = this.parent.objFramework.leftViewWidth;
        this.move(true);
    }
    else if(this.curActionWnd.tool.target == "right")
    {
        this.wndLeft = 0;
        this.wndRight = 0;
        this.move(true);
    }
}

function hide_wndctrl(id)
{
    if (!this.curActionWnd)
    {
        return;
    }
    if (this.timer)
    {
        clearTimeout(this.timer);
    }
    this.move(false);
}

function move_wndctrl(bShow)
{
    var inc = 50;
    var bEnd = false;
    var vType = this.curActionWnd.tool.target;
    var objStyle = $(vType + "_view").style;
    var vPos = objStyle.left.split("px")[0]*1;
    if (vType == "left" && bShow)
    {
        vPos += inc;
        this.wndLeft -= inc;
        if (this.wndLeft <= 0)
        {
            vPos += this.wndLeft;
            this.wndLeft = 0;
            bEnd = true;
        }
    }
    else if (vType == "left" && !bShow)
    {
        vPos -= inc;
        this.wndLeft = this.wndLeft*1 + inc;
        if (this.wndLeft >= this.wndRight)
        {
            vPos += this.wndLeft - this.wndRight;
//            this.wndLeft = this.wndRight;
            bEnd = true;
        }
    }
    else if (vType == "right" && bShow)
    {
        vPos -= inc;
        this.wndRight = this.wndRight*1 + inc;
        if (this.wndRight >= this.parent.objFramework.rightViewWidth)
        {
            vPos += this.wndRight - this.parent.objFramework.rightViewWidth + 3;
            this.wndRight = this.parent.objFramework.rightViewWidth;
            bEnd = true;
        }
    }
    else if (vType == "right" && !bShow)
    {
        vPos += inc;
        this.wndRight -= inc;
        if (this.wndRight <= 0)
        {
            vPos += this.wndRight;
            this.wndRight = 0;
            bEnd = true;
        }
    } 

    objStyle.clip = "rect(0 " + this.wndRight + "px auto " + this.wndLeft + "px)";
    objStyle.left = vPos + "px";
    if(!bEnd)
    {
        this.timer = setTimeout(this.name + ".move(" + bShow + ")", 50);
    }
}

function closeCurWnd_wndctrl(target)
{
    var objWnd = this.getCurWnd(target);
    if (objWnd)
    {
        //this.remove(objWnd.tool.id);
        this.parent.objBarCtrl.remove(objWnd.tool.id);
    }
}

function toggle_wndctrl(target)
{
    var framework = this.parent.objFramework;
    var arrWnd = this.getWndByType(target);
    if (target == "left")
    {
        if (framework.docBodyLeftState == 0)
        {
            framework.docBodyLeftState = 1;
            for (var i = 0; i < arrWnd.length; i++)
            {
                $(arrWnd[i].toggleId).innerHTML = '<img src="images/float.gif" alt="浮动" title="浮动" />';
            }
        }
        else
        {
            framework.docBodyLeftState = 0;
            for (var i = 0; i < arrWnd.length; i++)
            {
                $(arrWnd[i].toggleId).innerHTML = '<img src="images/static.gif" alt="固定" title="固定" />';
            }
        }
    }
    else if (target == "right")
    {
        if (framework.docBodyRightState == 0)
        {
            framework.docBodyRightState = 1;
            for (var i = 0; i < arrWnd.length; i++)
            {
                $(arrWnd[i].toggleId).innerHTML = '<img src="images/float.gif" alt="浮动" title="浮动" />';
            }
        }
        else
        {
            framework.docBodyRightState = 0;
            for (var i = 0; i < arrWnd.length; i++)
            {
                $(arrWnd[i].toggleId).innerHTML = '<img src="images/static.gif" alt="固定" title="固定" />';
            }
        }
    }
    else
    {
        return;
    }
    framework.reset();
    var curWnd = this.getCurWnd(target);
    if (curWnd)
    {
        this.parent.objBarCtrl.adjustBar(curWnd.tool.id);
        curWnd = this.getCurWnd("main");
        this.parent.objBarCtrl.adjustBar(curWnd.tool.id);
    }
//    for (var i = 0; i < this.arrWnd.length; i++)
//    {
//        if (this.arrWnd[i].tool.target == target)
//        {
//            this.adjustWnd(this.arrWnd[i])
//        }
//    }
    //调整view;
}

function adjustWnd_wndctrl(objWnd)
{
    var framework = this.parent.objFramework;
    var border = 2;
    var toolbarHeight = 0;
    switch (objWnd.tool.target)
    {
        case "left":
        {
            //工具条

            if (objWnd.toolbarCtrl.arrToolbar.length > 0)
            {
                 $(objWnd.toolbarId).show();
                 toolbarHeight = framework.leftToolbarHeight;
            }
            else
            {
                $(objWnd.toolbarId).hide();
                toolbarHeight = 0;
            }
            
            //状态变换标志

//            if (framework.docBodyLeftState == 1)
//            {
//                $(objWnd.toggleId).innerHTML = "H";
//                var elem = $(objWnd.wndId);
//                elem.onmouseout = null;
//                elem.onmouseover = null;
//            }
//            else if (framework.docBodyLeftState == 0)
//            {
//                $(objWnd.toggleId).innerHTML = "E";
//                var elem = $(objWnd.wndId);
//                elem.objWnd = objWnd;//存储对象
//                elem.objWndCtrl = this;
//                elem.onmouseout = function (evt)
//                {
//                    this.objWndCtrl.mouseOut(evt, this, this.objWnd.tool.id);
//                }
//                elem.onmouseover = function (evt)
//                {
//                    this.objWndCtrl.show(this.objWnd.tool.id);
//                }
//            }
//            
            $(objWnd.titleId).parentNode.style.height = framework.leftTitleHeight + "px";
            $(objWnd.contentId).style.height = framework.leftWndHeight - framework.leftTitleHeight - toolbarHeight - border + "px";
            $(objWnd.iframeId).style.height = framework.leftWndHeight - framework.leftTitleHeight - toolbarHeight - border + "px";
        }break;
        case "main":
        {
            if (objWnd.toolbarCtrl.arrToolbar.length > 0)
            {
                 $(objWnd.toolbarId).show();
                 toolbarHeight = framework.mainToolbarHeight;
            }
            else
            {
                $(objWnd.toolbarId).hide();
                toolbarHeight = 0;
            }
            $(objWnd.titleId).parentNode.style.display = "none";
            $(objWnd.contentId).style.height = framework.mainWndHeight - toolbarHeight + "px";
            $(objWnd.iframeId).style.height = framework.mainWndHeight - toolbarHeight + "px";
        }break;
        case "right":
        {
            if (objWnd.toolbarCtrl.arrToolbar.length > 0)
            {
                 $(objWnd.toolbarId).show();
                 toolbarHeight = framework.rightToolbarHeight;
            }
            else
            {
                $(objWnd.toolbarId).hide();
                toolbarHeight = 0;
            }
            
            //状态变换标志

//            if (framework.docBodyRightState == 1)
//            {
//                $(objWnd.toggleId).innerHTML = "H";
//                var elem = $(objWnd.wndId);
//                elem.onmouseout = null;
//                elem.onmouseover = null;
//            }
//            else if (framework.docBodyRightState == 0)
//            {
//                $(objWnd.toggleId).innerHTML = "E";
//                var elem = $(objWnd.wndId);
//                elem.objWnd = objWnd;//存储对象
//                elem.objWndCtrl = this;
//                elem.onmouseout = function (evt)
//                {
//                    this.objWndCtrl.mouseOut(evt, this, this.objWnd.tool.id);
//                }
//                elem.onmouseover = function (evt)
//                {
//                    this.objWndCtrl.show(this.objWnd.tool.id);
//                }
//            }
            $(objWnd.titleId).parentNode.style.height = framework.rightTitleHeight + "px";
            $(objWnd.contentId).style.height = framework.rightWndHeight - framework.rightTitleHeight - toolbarHeight - border + "px";
            $(objWnd.iframeId).style.height = framework.rightWndHeight - framework.rightTitleHeight - toolbarHeight - border + "px";
        }break;
        default:break;
    }
}


function getWndById_wndctrl(id)
{
    var objWnd = null;
    for (var i = 0; i < this.arrWnd.length; i++)
    {
        if (this.arrWnd[i].tool.id == id)
        {
            objWnd = this.arrWnd[i];
            break;
        }
    }
    return objWnd;
}

function getWndByType_wndctrl(target)
{
    var arrWnd = new Array();
    for (var i = 0; i < this.arrWnd.length; i++)
    {
        if (this.arrWnd[i].tool.target == target )
        {
            arrWnd.push(this.arrWnd[i]);
        }
    }
    return arrWnd;
}

function getCurWnd_wndctrl(target)
{
    var objWnd = null;
    for (var i = 0; i < this.arrWnd.length; i++)
    {
        if ((this.arrWnd[i].tool.target == target)
            && (this.arrWnd[i].isCurWnd))
        {
            objWnd = this.arrWnd[i];
            break;
        }
    }
    return objWnd;
}
/////////////////窗体对象///////////////
function create_wnd()
{
    var vHtml = '<div id="' + this.wndId + '" class="one_wnd">'
              + '<div class="title">'
              + '<span id="' + this.titleId + '" class="wnd_title">' + this.tool.name + '</span>'
              + '<div class="wnd_ctrl">'
              + '<span onclick="' + this.parent.name + '.hide(' + this.tool.id + ');"><img src="images/min.gif" alt="隐藏" title="隐藏" /></span>&nbsp;'
              + '<span id="' + this.toggleId + '" onclick="' + this.parent.name + '.toggle(\'' + this.tool.target + '\');"><img src="images/float.gif" alt="浮动" title="浮动"/></span>&nbsp;'
              + '<span onclick="' + this.parent.parent.objBarCtrl.name + '.remove(' + this.tool.id + ');"><img src="images/close.gif" alt="关闭" title="关闭"/></span></div>'
              + '</div>'
              + '<div id="' + this.toolbarId + '" class="toolbar"></div>'
              + '<div id="' + this.contentId + '" class="content" height="100px">'
              + '<iframe id="' + this.iframeId + '" frameborder="0" src="' + this.tool.url + '" height="100%" width="100%" ' 
//              + ' onload="top.m_doc.loading();"'
//              + ' onmouseover="' + this.parent.name + '.show(' + this.tool.id + ');"'
//              + ' onmouseout="' + this.parent.name + '.mouseOut(event, this,' + this.tool.id + ');"'
              + ' ></iframe>'
              + '</div>'
              + '</div>';
    //var elem = document.createElement(vHtml);
    //$(this.wndCtrlId).insertAdjacentHTML("beforeEnd", vHtml);
    new Insertion.Bottom(this.wndCtrlId, vHtml);
}

function show_wnd()
{
    $(this.wndId).show();
    this.isCurWnd = true;
}

function hide_wnd()
{
    $(this.wndId).hide();
    this.isCurWnd = false;
}

function delete_wnd()
{
    $(this.wndId).remove();
}

function update_wnd(newTool)
{
    if (newTool.title && this.tool.title != newTool.title)
    {
        $(this.titleId).innerHTML = newTool.title;
        this.tool.title = newTool.title;
    }
    if (newTool.url && this.tool.url != newTool.url)
    {
        $(this.iframeId).src = newTool.url;
        this.tool.url = newTool.url;
    }
    if (newTool.target && this.tool.target != newTool.target)
    {
        $(newTool.target + "_wnd").appendChild($(this.wndId));
        this.tool.target = newTool.target;
    }
}

////////////////选择栏控制器//////////////////
function append_barctrl(tool)
{
    var objBar = null;
    for (var i = 0; i < this.arrBar.length; i++)
    {
        if ( this.arrBar[i].tool.id == tool.id)
        {
            objBar = this.arrBar[i];
            break;
        }
    }
    if (objBar)
    {
        if(tool.target == "float")
        {
            this.remove(tool.id);
        }
        else
        {
            objBar.update(tool);
            this.setActive(tool.id);
        }
    }
    else
    {
        objBar = new CtnBar(this, tool);
        objBar.create();
        this.arrBar.push(objBar);
    }
    this.setActive(tool.id);
    this.adjustBar(tool.id);
}

function showAllBar_barctrl(evt, elem, target)
{
    var arrBar = this.getBarByType(target);
    if (this.barlist)
    {
        this.barlist.hide();
    }
    this.barlist = new CtnMenuCtrl(this.name + ".barlist", false, true, "bar_list");
    this.barlist.outHide();
    for (var i = 0; i < arrBar.length; i++)
    {
        this.barlist.addEvent(arrBar[i].tool.name,
             this.name + ".setActive('" + arrBar[i].tool.id + "');" + 
             this.name + ".adjustBar('" + arrBar[i].tool.id + "');" + 
             this.parent.objWndCtrl.name + ".setActive('" + arrBar[i].tool.id + "');");
    }
    this.barlist.show(evt,elem);
}

function adjustBar_barctrl(id)
{
    var objBar = this.getBarById(id); 
    var framework = this.parent.objFramework;
    var bar = null;
    var barctrl = null;
    var ul = null;
    var li = null;
    
    if (objBar.tool.target == "main")
    {
        li = $(objBar.barId);
        bar = li.parentNode.parentNode;
        ul = bar.getElementsByTagName("ul")[0];
        barctrl = bar.getElementsByTagName("ul")[1];
    }
    else if ((objBar.tool.target == "left" && framework.docBodyLeftState != 0)
            || (objBar.tool.target == "right" && framework.docBodyRightState != 0))
    {
        li = $(objBar.barXId);
        bar = li.parentNode.parentNode;
        ul = bar.getElementsByTagName("ul")[0];
        barctrl = bar.getElementsByTagName("ul")[1];
    }
    else if ((objBar.tool.target == "left")|| (objBar.tool.target == "right"))
    {
        li = $(objBar.barYId);
        bar = li.parentNode.parentNode;
        ul = bar.getElementsByTagName("ul")[1];
        barctrl = bar.getElementsByTagName("ul")[0];
    }
    else
    {
        return;
    }
    
    li.show();
    //针对Y轴Bar
    if ((objBar.tool.target == "left" && framework.docBodyLeftState == 0)
       || (objBar.tool.target == "right" && framework.docBodyRightState == 0))
    {
        var bodyHeight = framework.docBodyHeight;
        var footTop = framework.frameworkHeight - framework.docFootHeight - 5;
        var bodyTop = footTop - framework.docBodyHeight + 5;
        var lastLi = ul.lastChild;
        //前者针对IE，后者针对FireFox
        if ((ul.offsetHeight + barctrl.offsetHeight > bodyHeight) && CtnBrowser.IE6
        ||(lastLi.offsetTop + lastLi.offsetHeight + bodyTop > footTop) && CtnBrowser.IE7
            ||(lastLi.offsetTop + lastLi.offsetHeight > footTop) && CtnBrowser.FF)
        {
            ul.style.backgroundColor="red";
            var vCount = ul.childNodes.length;
            for (var i = 0; i < vCount; i++)
            {
                var elem = ul.childNodes[i];
                if (elem.style.display != "none" && elem != li)
                {
                    elem.style.display = "none";
                    ul.appendChild(elem);//???解决IE6显示 Bug,将隐藏元素滞后

                    if ((ul.offsetHeight + barctrl.offsetHeight > bodyHeight && CtnBrowser.IE6)
                        ||(lastLi.offsetTop + lastLi.offsetHeight + bodyTop > footTop) && CtnBrowser.IE7
                        ||(lastLi.offsetTop + lastLi.offsetHeight > footTop) && CtnBrowser.FF)
                    {
                        vCount--;
                        i--;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        else
        {
            //删除后，如果不够则补上

            for (var i = 0; i < ul.childNodes.length ; i++)
            {
                var elem = ul.childNodes[i];
                if (elem.style.display == "none")
                {
                    elem.style.display = "block";
                    if ((ul.offsetHeight + barctrl.offsetHeight > bodyHeight) && CtnBrowser.IE6
                        ||(lastLi.offsetTop + lastLi.offsetHeight + bodyTop > footTop) && CtnBrowser.IE7
                        ||(elem.offsetTop + elem.offsetHeight > footTop) && CtnBrowser.FF)
                    {
                        elem.style.display = "none";
                    }
                }
            }
        }
    }
    else
    {
        //判断是否越界
        //前者针对IE，后者针对FireFox
        if (((bar.offsetHeight > ul.offsetHeight + 10) && CtnBrowser.IE6)
            ||((ul.offsetTop < barctrl.offsetTop - 5) && !CtnBrowser.IE6))
        {
            ul.appendChild(li);//在最后显示

            for (var i = 0; i < ul.childNodes.length; i++)
            {
                var elem = ul.childNodes[i];
                if (elem.style.display != "none" && elem != li)
                {
                    elem.style.display = "none";
                    if (((bar.offsetHeight > ul.offsetHeight + 8) && CtnBrowser.IE6)
                        ||((ul.offsetTop < barctrl.offsetTop - 5) && !CtnBrowser.IE6))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        else
        {
            //删除后，如果不够则补上

            for (var i = 0; i < ul.childNodes.length ; i++)
            {
                var elem = ul.childNodes[i];
                if (elem.style.display == "none")
                {
                    elem.style.display = "block";
                    if (((bar.offsetHeight > ul.offsetHeight + 8) && CtnBrowser.IE6)
                        ||((ul.offsetTop < barctrl.offsetTop - 5) && !CtnBrowser.IE6))
                    {
                        elem.style.display = "none";
                        break;
                    }
                }
            }
        }
    }
    
    //将隐藏元素滞后
    for (var i = ul.childNodes.length - 1; i >= 0 ; i--)
    {
        var elem = ul.childNodes[i];
        if (elem.style.display == "none")
        {
            ul.appendChild(elem);
        }
    }
}

function remove_barctrl(id)
{
    for (var i = 0; i < this.arrBar.length; i++)
    {
        if (this.arrBar[i].tool.id == id)
        {
            var target = this.arrBar[i].tool.target;
            var framework = this.parent.objFramework;
            var li = null;
            if(target == "main")
            {
                li = $(this.arrBar[i].barId);
            }
            else if ((target == "left" && framework.docBodyLeftState != 0)
                || (target == "right" && framework.docBodyRightState != 0))
            {
                li = $(this.arrBar[i].barXId);
            }
            else
            {
                li = $(this.arrBar[i].barYId);
            }
            //取前一个或后一个

            if (li.previousSibling) //&& li.className.indexOf("current") > -1
            {
                li = li.previousSibling;
            }
            else if (li.nextSibling)// && li.className.indexOf("current") > -1
            {
                li = li.nextSibling;
            }
            else
            {
                li = null;
            }

            this.arrBar[i].del();
            this.arrBar.splice(i, 1);
            this.parent.objWndCtrl.remove(id);
            
            if (li)
            {
                var toolid = li.id.split("_")[1];
                this.setActive(toolid);
                this.parent.objWndCtrl.setActive(toolid);
                this.adjustBar(toolid);
            }
            break;
        }
    }
}

function setActive_barctrl(id)
{
    var objBar = this.getBarById(id);
    //显示当前页

    for (var i = 0; i < this.arrBar.length; i++)
    {
        if (this.arrBar[i].tool.id == id)
        {
            this.arrBar[i].show();
        }
        else if (this.arrBar[i].tool.target == objBar.tool.target)
        {
            this.arrBar[i].hide();
        }
    }
}

function getBarByType_barctrl(target)
{
    var arrBar = new Array();
    for (var i = 0; i < this.arrBar.length; i++)
    {
        if (this.arrBar[i].tool.target == target)
        {
            arrBar.push(this.arrBar[i]);
        }
    }
    return arrBar;
}

function getBarById_barctrl(id)
{
    var objBar = null;
    for (var i = 0; i < this.arrBar.length; i++)
    {
        if (this.arrBar[i].tool.id == id)
        {
            objBar = this.arrBar[i];
            break; 
        }
    }
    return objBar;
}



/////////////////选择栏////////////////////////
function create_bar()
{
    var vHtml = new String();
    var vBefore = '<li id="';
    var vStatic = '" onclick="' + this.parent.name + '.setActive(' + this.tool.id + ');'
         + this.parent.parent.objWndCtrl.name + '.setActive(' + this.tool.id + ');"'
        + ' onmouseover="this.className += \' hover\';"'
        + ' onmouseout="this.className = this.className.replace(\'hover\',\'\');"';
    var vFloat = '" onclick="' + this.parent.name + '.setActive(' + this.tool.id + ');'
        + this.parent.parent.objWndCtrl.name + '.show(' + this.tool.id + ');'
        + '" onmouseover="this.className += \' hover\';'
 //       + this.parent.parent.objWndCtrl.name + '.show(' + this.tool.id + ');'
        + '" onmouseout="this.className = this.className.replace(\'hover\',\'\');'
//        + this.parent.parent.objWndCtrl.name + '.mouseOut(event, this, ' + this.tool.id + ');';
    var vAfter = '" ondblclick="'
        + this.parent.name + '.remove(' + this.tool.id + ');'
//        + this.parent.parent.objWndCtrl.name + '.remove(' + this.tool.id + ');'
        + '">' + this.tool.name + '</li>';
    switch (this.tool.target)
    {
        case "left":
        {
//            $(m_def.leftUlBarX).insertAdjacentHTML("beforeEnd", vBefore + this.barXId + vStatic + vAfter);
//            $(m_def.leftUlBarY).insertAdjacentHTML("beforeEnd", vBefore + this.barYId + vFloat + vAfter);
            new Insertion.Bottom(m_def.leftUlBarX, vBefore + this.barXId + vStatic + vAfter);
            new Insertion.Bottom(m_def.leftUlBarY, vBefore + this.barYId + vFloat + vAfter);
        }break;
        case "main":
        {
//            $(m_def.mainUlBar).insertAdjacentHTML("beforeEnd", vBefore + this.barId + vStatic + vAfter);
            new Insertion.Bottom(m_def.mainUlBar, vBefore + this.barId + vStatic + vAfter);
        }break;
        case "right":
        {
            //$(m_def.rightUlBarX).insertAdjacentHTML("beforeEnd", vBefore + this.barXId + vStatic + vAfter);
            //$(m_def.rightUlBarY).insertAdjacentHTML("beforeEnd", vBefore + this.barYId + vFloat + vAfter);
            new Insertion.Bottom(m_def.rightUlBarX, vBefore + this.barXId + vStatic + vAfter);
            new Insertion.Bottom(m_def.rightUlBarY, vBefore + this.barYId + vFloat + vAfter);
        }break;
        default:
        return null;
    }
}

function show_bar()
{
    switch (this.tool.target)
    {
        case "left":
        {
            $(this.barXId).addClassName("current");
            $(this.barYId).addClassName("current");
        }break;
        case "main":
        {
            $(this.barId).addClassName("current");
        }break;
        case "right":
        {
            $(this.barXId).addClassName("current");
            $(this.barYId).addClassName("current");
        }break;
        default:
        return null;
    }
}

function hide_bar()
{
    switch (this.tool.target)
    {
        case "left":
        {
            $(this.barXId).removeClassName("current");
            $(this.barYId).removeClassName("current");
        }break;
        case "main":
        {
            $(this.barId).removeClassName("current");
        }break;
        case "right":
        {
            $(this.barXId).removeClassName("current");
            $(this.barYId).removeClassName("current");
        }break;
        default:
        return null;
    }
}

function delete_bar()
{
    switch (this.tool.target)
    {
        case "left":
        {
            $(this.barXId).remove();
            $(this.barYId).remove();
        }break;
        case "main":
        {
            $(this.barId).remove();
        }break;
        case "right":
        {
            $(this.barXId).remove();
            $(this.barYId).remove();
        }break;
        default:
        return null;
    }
}

function update_bar(newTool)
{
    switch (newTool.target)
    {
        case "left":
        {
            $(this.barXId).innerHTML = newTool.name;
            $(this.barYId).innerHTML = newTool.name;
            if (this.tool.target != newTool.target)
            {
                $(m_def.leftUlBarX).appendChild($(this.barXId));
                $(m_def.leftUlBarY).appendChild($(this.barYId));
            }
        }break;
        case "main":
        {
            $(this.barId).innerHTML = newTool.name;
        }break;
        case "right":
        {
            $(this.barXId).innerHTML = newTool.name;
            $(this.barYId).innerHTML = newTool.name;
            if (this.tool.target != newTool.target)
            {
                $(m_def.rightUlBarX).appendChild($(this.barXId));
                $(m_def.rightUlBarY).appendChild($(this.barYId));
            }
        }break;
        default:
        return null;
    }
}

////////////////Tool对象//////////////////////

////////////////工具条控制器//////////////////

///////////////工具栏对象//////////////////////
function append_tb(vTool)
{
}
function update_tb(vTool)
{
}
function delete_tb(vTool)
{
}

function active_tb(vTool)
{
}
